From 2c32f7df21a2a293846c67fab1f544029b955e98 Mon Sep 17 00:00:00 2001 From: River Tarnell Date: Tue, 21 Sep 2004 11:54:45 +0000 Subject: [PATCH] fix for several problems found by Eloquence: section edit links in nested templates didn't work; edit links for subsections in templates didn't work. pending: links for non-existent templates are broken. --- includes/Parser.php | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index 5e4915434c..dd1a3bb41f 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -52,8 +52,6 @@ define( 'EXT_IMAGE_REGEX', '('.EXT_IMAGE_FNAME_CLASS.'+)\\.((?i)'.EXT_IMAGE_EXTENSIONS.')$/S' # Filename ); -$wgCurrentSectionNumber = 0; # XXX - /** * PHP Parser * @@ -1849,15 +1847,27 @@ class Parser # replace ==section headers== # XXX this needs to go away once we have a better parser. if ( $this->mOutputType != OT_WIKI ) { - $encodedname = base64_encode($title->getPrefixedDBkey()); - $wfCurrentSectionNumber = 0; - for ( $i = 1; $i <= 6; ++$i ) { - $h = substr( '======', 0, $i ); - $text = preg_replace_callback( "/^({$h})([^=].*){$h}\\s?$/m", - create_function('$matches', -'return "${matches[1]}$matches[2] __MWTEMPLATESECTION='.$encodedname. -'&" . wfGetSectionNumber() . "__${matches[1]}";' - ), $text); + if( !is_null( $title ) ) + $encodedname = base64_encode($title->getPrefixedDBkey()); + else + $encodedname = base64_encode(""); + $matches = preg_split('/(^={1,6}.*?={1,6}\s*?$)/m', $text, -1, + PREG_SPLIT_DELIM_CAPTURE); + $text = ''; + $nsec = 0; + for( $i = 0; $i < count($matches); $i += 2 ) { + if ($matches[$i] == "" && $matches[$i + 1] == "") break; + $text .= $matches[$i]; + $hl = $matches[$i + 1]; + if( strstr($hl, "__MWTEMPLATESECTION") ) { + $text .= $hl; + continue; + } + preg_match('/^(={1,6})(.*?)(={1,6})\s*?$/m', $hl, $m2); + $text .= $m2[1] . $m2[2] . "__MWTEMPLATESECTION=" + . $encodedname . "&" . base64_encode("$nsec") . "__" . $m2[3]; + + $nsec++; } } return $text; @@ -2239,7 +2249,7 @@ class Parser if( $doShowToc && ( !isset($wgMaxTocLevel) || $toclevel<$wgMaxTocLevel ) ) { $toc .= $sk->tocLine($anchor,$tocline,$toclevel); } - if( $showEditLink ) { + if( $showEditLink && ( !$istemplate || $templatetitle !== "" ) ) { if ( empty( $head[$headlineCount] ) ) { $head[$headlineCount] = ''; } @@ -2800,10 +2810,4 @@ function wfEscapeHTMLTagsOnly( $in ) { $in ); } -function wfGetSectionNumber() { - global $wgCurrentSectionNumber; - $str = base64_encode("$wgCurrentSectionNumber"); - $wgCurrentSectionNumber++; - return $str; -} ?> -- 2.20.1